home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1671 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  57 lines

  1. Path: colossus.holonet.net!mitch
  2. From: mitch@news.mdli.com (Mitch Miller)
  3. Newsgroups: comp.lang.c
  4. Subject: Pointer-to-Double as Function Arg
  5. Date: 16 Jan 1996 05:17:08 GMT
  6. Organization: HoloNet National Internet Access System: 510-704-1058/modem
  7. Message-ID: <4dfccl$j5h@colossus.holonet.net>
  8. NNTP-Posting-Host: jubal.mdli.com
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. I'm having a problem with a function that takes a
  12. couple of pointer-to-double arguments, initializes then
  13. and assigns values to them in an array style:
  14.  
  15. Function is something like:
  16.  
  17.     int GetValue( long iDim, double * Values1, double *
  18.       Values2 )
  19.     {
  20.         int iter;
  21.         Values1 = (double *) malloc( iDim * sizeof( double ));
  22.         if (Values1 == NULL )
  23.             ....
  24.         Values2 = (double *) malloc( iDim * sizeof( double ));
  25.         if (Values2 == NULL )
  26.             ...
  27.  
  28.         for (iter=1; iter<iDim; iter++)
  29.         {
  30.             Values1[iter] = ...;
  31.             Values2[iter] = ...;
  32.  
  33.         }
  34.  
  35.         return 1;
  36.     }
  37.  
  38. Call from main:
  39.  
  40.     double * Ptr1;
  41.     double * Ptr2;
  42.  
  43.     if (!GetValue( iSize, Ptr1, Ptr2 ) )....
  44.  
  45.  
  46. When I look at the values of Values1 and Values2 in GetValue, they have
  47. the correct values.
  48.  
  49. However, back in main, they have NULL values.
  50.  
  51. If I make Ptr1 and Ptr2 global variables so that they are not included
  52. in the function calls, the code works fine.
  53.  
  54. I've checked the FAQs, but couldn't find anything quite like this.
  55.  
  56. Thanks in advance... 
  57.